import { type XFormApi } from './types/types'
import { ref } from 'vue'

/**
 * 注册组件
 * @returns
 * @example const api = useXFormApi(); api().register
 */
export const useXFormApi = <
  TFormData extends Record<string, any> = Record<string, any>,
>(): XFormApi<TFormData> => {
  let api = ref<XFormApi<TFormData>>({} as XFormApi<TFormData>)
  api.value.register = (tempApi: XFormApi<TFormData>) => {
    api.value = tempApi
    return api
  }
  return api as unknown as XFormApi<TFormData>
}
